/*
Copyright 2005-2014 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.instructional.example.thread;

import java.io.PrintStream;

public class Notifier_01 {
    final private Monitor     monitor;
    final private PrintStream out;
    final private String      className = this.getClass().getSimpleName();

    public Notifier_01(final PrintStream out, final Monitor monitor) {
        this.monitor = monitor;
        this.out = out;
        out.println("Class construction complete.");
    }

    public void notifier() {
        out.println("notifier() - Entry");
        final Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                out.println("notifier() - Thread.run() - entry");
                synchronized (monitor) {
                    monitor.isNotified = true;
                    out.println("notifier() - Thread.run() - sendiing notify...");
                    monitor.notify();
                    out.println("notifier() - Thread.run() - notify sent...");
                }
                out.println("notifier() - Thread.run() - exit");
            }
        });
        t.setDaemon(true);
        t.start();
        out.println("notifier() - Exit");
    }
}
